/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package titanisu.basicMathModule1.FractionMultiplication;

import titanisu.basicMathModule1.mixedtpproperfractionVonversion.*;
import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author Balaji
 */
public class QuestionGeneratorAddSub {

    ArrayList quest = new ArrayList();

    private void setQ(ArrayList arlst) {
        this.quest = arlst;
    }

    public ArrayList getQuest() {
        return quest;
    }

    public void setQuest(ArrayList quest) {
        this.quest = quest;
    }

    public String getQuestions() {
        /*
         int variables[] = new int[5];
         for (int i = 0; i < variables.length; i++) {
         variables[i] = (new Random()).nextInt(9) + 1;
         }
         */
        int w = (new Random()).nextInt(9) + 1, x = (new Random()).nextInt(9) + 1, y = (new Random()).nextInt(9) + 1, z = (new Random()).nextInt(9) + 1;
        String op = "";
        titanisu.templates.helperClasses.VariablesHelper mh = new titanisu.templates.helperClasses.VariablesHelper();
        op = mh.getRandomOperator("X/");
        int[] an;
        int den = -1;
        int nom , denom;
        if (op == "X") {

            an = new titanisu.mathUtil.NumberFetcher().simplifyFraction((y * w), (x * z));
            den = an[1];
            nom = y*w;
            denom = x*z;
        } else {
            an = new titanisu.mathUtil.NumberFetcher().simplifyFraction((z * w), (x * y));
            den = an[1];
            nom = z*w;
            denom = x*y;
        }
        quest.add(0, "<math>   <mfrac>       <mi> " + w + " </mi>  <mi> " + x + " </mi>    </mfrac>  <mo>" + op + " </mo> <mfrac>       <mi> " + y + " </mi>  <mi> " + z + " </mi>    </mfrac>  </math>  ");

        if (den != 1) {
            if ((den != x*z && op=="X" ) || (den != x*y && op=="/" ) ) {
                quest.add(1, "" + "<math>   <mfrac>       <mi> " + an[0] + " </mi>  <mi> " + an[1] + " </mi>    </mfrac> <mi> or </mi>  <mfrac>       <mi> " + nom + " </mi>  <mi> " + denom + " </mi>    </mfrac> </math>  ");
            } else {
                quest.add(1, "" + "<math>   <mfrac>       <mi> " + an[0] + " </mi>  <mi> " + an[1] + " </mi>    </mfrac>  </math>  ");
            }


        } else {
            if ((den != x*z && op=="X" ) || (den != x*y && op=="/" ) ) {
                quest.add(1, "" + "<math>    <mi> " + an[0] + " </mi>  <mi>or</mi>  <mfrac>       <mi> " + an[0] + " </mi>  <mi> " + an[1] + " </mi>    </mfrac> <mi> or </mi>  <mfrac>       <mi> " + nom + " </mi>  <mi> " + denom + " </mi>    </mfrac>  </math>  ");
            } else {
                quest.add(1, "" + "<math>    <mi> " + an[0] + " </mi>  <mi>or</mi>  <mfrac>       <mi> " + an[0] + " </mi>  <mi> " + an[1] + " </mi>    </mfrac> </math>  ");
            }
        }

        setQ(quest);
        System.out.println(" quest set in questionGenerator is " + quest);
        return (String) quest.get(0);
    }

    /**
     * Gives the answers
     *
     * @return
     */
    public String getAnswer() {
        return (String) quest.get(1);
    }
}
